﻿using System.Windows;
using PasswordControl.UI.WPF.ViewModel.PackageProvider;
using Microsoft.Win32;
using PasswordControl.UI.WPF.Data;

namespace PasswordControl.UI.WPF
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private PackageProviderViewModel m_packageProviderViewModel = new PackageProviderViewModel();

        public MainWindow()
        {
            InitializeComponent();

            m_packageProviderViewModel.PackagePath = UserData.Instance.LastComponentPath;
            DataContext = m_packageProviderViewModel;
        }

        private void PackageBrowseButton_Click(object sender, RoutedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog();
            openFileDialog.AddExtension = true;
            openFileDialog.DefaultExt = ".sod";
            openFileDialog.Multiselect = false;
            openFileDialog.CheckFileExists = true;
            openFileDialog.Title = "Open Password File";
            openFileDialog.Filter = "Password Files (.sod)|*.sod";

            bool? result = openFileDialog.ShowDialog();
            if (result != true) return;

            m_packageProviderViewModel.PackagePath = openFileDialog.FileName;
        }

        private void PackagePassword_PasswordChanged(object sender, RoutedEventArgs e)
        {
            m_packageProviderViewModel.Password = PackagePassword.Password;
        }
    }
}
